package com.preguicoso.server.integracao;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.preguicoso.server.cadastro.CadastroServiceImpl;
import com.preguicoso.shared.entities.ItemCardapioBean;
import com.preguicoso.shared.entities.PedidoBean;

public class PedidoDataSet extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	      throws ServletException, IOException {
		
		PrintWriter out = resp.getWriter();
			
		CadastroServiceImpl pedido = new CadastroServiceImpl();
		ArrayList<PedidoBean> pedidos = (ArrayList<PedidoBean>) pedido.getPedidosNovos(Long.parseLong(req.getParameter("id")), new Date());
		
		int count = 0;
		for (PedidoBean pedidoBean : pedidos) {
			for (ItemCardapioBean i : pedidoBean.getListaItens()) {
				count++;
			}
		}
		out.println("[{");
		out.println("\"DataSetName\":\"Pedido_DataSet\",");
		out.println("\"DataSetCount\":"+count+",");
		out.println("\"DataFieldList\":");
		for (PedidoBean pedidoBean : pedidos) {
			for (ItemCardapioBean i : pedidoBean.getListaItens()) {
				out.println("[{");
				out.println("\"Produto\":\""+i.getNumero()+"\",");
				out.println("\"Qtd\":\""+i.getQuantidade()+"\",");
				out.println("\"Obs\":\""+i.getObservacao()+"\",");
				out.println("\"Garcon\":\"302\",");
				out.println("\"Atendimento\":\"0\",");
				out.println("\"Localizacao\":\"0\",");
				out.println("\"Cliente\":\"2654\"");
				out.println("}]");
			}
		}
		out.println("]}");
	  }
}
